# pytest+requests+allure
import pytest
import allure
import requests
from faker import Faker
faker = Faker(locale='zh_cn')
url = "http://119.29.229.84:8899"
@allure.feature("crmeb用户分组流程")
class TestGroup:
    @pytest.fixture(scope='function')
    def login(self):
        # 发起登录请求
        response = requests.post(url = url+"/adminapi/login",
                                 json={"account":"admin","pwd":"123456","key":"68622db52c3f1","captchaType":"blockPuzzle","captchaVerification":""})
        # 拿到token值
        token = response.json()['data']['token']
        yield token
    @allure.story("添加用户分组用例")
    def test_addGroup(self,login):
        # 发起新增请求
        response = requests.post(url=url+"/adminapi/user/user_group/save.html",json={"group_name":str(faker.name())},headers={"Authori-zation":"Bearer "+str(login)})
        # 断言响应结果
        assert response.status_code == 200
        assert response.json()['msg'] =='提交成功'

# pytest -s .\03-综合案例_test.py --alluredir=allure  执行测试用例，并生成结果集
# allure generate ./allure/ -o ./reports --clean   生成测试报告